/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;

/**
 *
 * @author dell
 */
public class ParserJson {

    public static List<Map<String, String>> getContent(String jsonString) throws Exception {
        List<Map<String, String>> rsList = new ArrayList<Map<String, String>>();
        JSONObject object = JSONObject.fromObject(jsonString);
        for (Iterator<?> iter = object.keys(); iter.hasNext();) {
            Map<String, String> map = new HashMap<String, String>();
            String key = (String) iter.next();
            String value = object.get(key).toString();
            map.put(key, value);
            rsList.add(map);
        }
        return rsList;
    }

    public static int getColumnCount(String jsonString) throws Exception {
        int count = 0;
        JSONObject object = JSONObject.fromObject(jsonString);
        count = object.size();
        return count;
    }
}
